<html>
<head><meta charset="utf-8"><title>Does rustc do any cross-crate inlining? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html">Does rustc do any cross-crate inlining?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183232411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183232411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183232411">(Dec 12 2019 at 06:38)</a>:</h4>
<p>I'm very new at rustc development -- I'm wondering if rustc does any cross-crate optimizations, and if it does where do I find the code that serializes/deserializes HIR/MIR for cross-crate inlining. Also, am I right that a crate is one compilation unit, and optimized/code generated as a whole? Thanks.</p>
<p>(I've searched about this but the term "cross" mostly brings cross-compilation related stuff. There's one blog post, but it's published in 2012 so it's probably not too relevant these days)</p>



<a name="183235510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183235510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183235510">(Dec 12 2019 at 07:58)</a>:</h4>
<p>Our optimizations do not care whether a function is from the same crate or from a different crate. I fact, except for lints the optimizations can't even tell the difference</p>



<a name="183235566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183235566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183235566">(Dec 12 2019 at 07:58)</a>:</h4>
<p>The (de-)serialization happens completely transparently in the query system</p>



<a name="183235580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183235580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183235580">(Dec 12 2019 at 07:59)</a>:</h4>
<p>You request the MIR of a function from another crate with the same query that you use for local crates</p>



<a name="183235828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183235828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183235828">(Dec 12 2019 at 08:02)</a>:</h4>
<p>That said, if you are still interested in metadata serialization and deserialization, the typr you want to look at is <code>CrateMetadata</code>. Although note that this is just a tiny cog in the metadata (de)serialization scheme.</p>



<a name="183235852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183235852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183235852">(Dec 12 2019 at 08:03)</a>:</h4>
<p>There may also be a rustc-guide topic about this, I'm not sure, search the guide for "metadata" I guess</p>



<a name="183252339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Does%20rustc%20do%20any%20cross-crate%20inlining%3F/near/183252339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Does.20rustc.20do.20any.20cross-crate.20inlining.3F.html#183252339">(Dec 12 2019 at 12:06)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="124288">@oli</span> , that's very helpful. I'll check the code and the rustc-guide section.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>